﻿using System;
using System.Collections.Generic;

namespace Data.Common
{
    /// <summary>
    ///     封装用于分页的数据集合
    /// </summary>
    [Serializable]
    public class PagingDataSet<T>
    {
        private int _pageIndex = 1;
        private int _pageSize = 20;
        private IList<T> _records;
        private int _totalRecords;

        /// <summary>
        ///     构造函数
        /// </summary>
        public PagingDataSet()
        {
            _records = new List<T>();
        }

        /// <summary>
        ///     构造函数
        /// </summary>
        /// <param name="records"></param>
        public PagingDataSet(IList<T> records)
        {
            if (records == null)
                _records = new List<T>();
            else
                _records = records;
        }

        /// <summary>
        ///     当前页的数据集合
        /// </summary>
        public IList<T> Records
        {
            get
            {
                if (_records == null)
                    _records = new List<T>();
                return _records;
            }
            set { _records = value; }
        }

        /// <summary>
        ///     每页显示记录数
        /// </summary>
        public int PageSize
        {
            get { return _pageSize; }
            set { _pageSize = value; }
        }

        /// <summary>
        ///     当前页数
        /// </summary>
        public int PageIndex
        {
            get { return _pageIndex; }
            set { _pageIndex = value; }
        }

        /// <summary>
        ///     总记录数
        /// </summary>
        public int TotalRecords
        {
            get { return _totalRecords; }
            set { _totalRecords = value; }
        }
    }
}